package doorwifi.wd.patientsation.peripheral.mainapp.fragment;


import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;

import doorwifi.wd.patientsation.peripheral.mainapp.Bean.CallLineUpInfo;
import doorwifi.wd.patientsation.peripheral.mainapp.Bean.illnessRoom;
import doorwifi.wd.patientsation.peripheral.mainapp.R;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.CallDoorIsTelInfoAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.CallLineUpInfoAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.Adapter.illnessDoorAdapter;
import doorwifi.wd.patientsation.peripheral.mainapp.utils.DividerGridItemDecoration;

/**
 * Created by xuhuan on 2017/7/6.
 *
 * 呼叫门口
 */

public class CallDoor extends Fragment implements illnessDoorAdapter.illnessDoorItemOnclickListener{

    @ViewInject(R.id.call_door_recyclerview)
    private RecyclerView call_door_recyclerview;

    @ViewInject(R.id.call_line_up_info_listview)
    private ListView call_line_up_info_listview;

    @ViewInject(R.id.is_telephone_info_listview)
    private ListView is_telephone_info_listview;

    private LinearLayoutManager manager;
    private ArrayList<illnessRoom> roomList;
    private illnessRoom room;
    private illnessDoorAdapter illnessDoorAdapter;
    private CallLineUpInfo lineUpInfo;
    private ArrayList<CallLineUpInfo> lineUpInfoList;
    private CallLineUpInfoAdapter lineUpinfoAdapter;
    private CallDoorIsTelInfoAdapter isTelInfoAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.xh_call_door_layout,null);
        x.view().inject(this,view);

        initDoor();//初始化门口机
        initCallLineUpInfo();//显示呼叫排队信息栏
        initIsTelInfo(); //初始化通话信息栏

        return view;
    }

    private void initIsTelInfo() {
        isTelInfoAdapter = new CallDoorIsTelInfoAdapter(getActivity(),"108房");
        is_telephone_info_listview.setAdapter(isTelInfoAdapter);
    }


    //获得呼叫排队信息栏数据
    private void initCallLineUpInfo() {
        getLineUpInfoData();
        lineUpinfoAdapter = new CallLineUpInfoAdapter(getActivity(),lineUpInfoList);
        call_line_up_info_listview.setAdapter(lineUpinfoAdapter);
    }

    public void getLineUpInfoData() {
        lineUpInfoList = new ArrayList<CallLineUpInfo>();
        for (int i = 3; i < 6; i++) {
            lineUpInfo = new CallLineUpInfo();
            lineUpInfo.setDate("2017-07-11");
            lineUpInfo.setTime("09:15:15");
            lineUpInfo.setIllnessRoom("102房");
            lineUpInfo.setIllnessBed(i + "房正在呼叫");
            lineUpInfoList.add(lineUpInfo);
        }
    }

    private void initDoor() {
        getDoorData();
        manager = new LinearLayoutManager(getActivity());
        //设置布局管理器
//        illnessDoor_recyclerview.setLayoutManager(manager);
        call_door_recyclerview.setLayoutManager(  new GridLayoutManager(getActivity(),6));
        illnessDoorAdapter = new illnessDoorAdapter(getActivity(),roomList);
        call_door_recyclerview.setAdapter(illnessDoorAdapter);
        call_door_recyclerview.addItemDecoration(new DividerGridItemDecoration(getActivity()));
        illnessDoorAdapter.setillnessDoorOnItemClickListener(this);
    }

    private void getDoorData() {
        roomList = new ArrayList<illnessRoom>();
        for(int i = 100; i < 130; i ++){
            room = new illnessRoom();
            room.setIllnessNumber(i+"房");
            roomList.add(room);
        }
    }

    @Override
    public void onSickDoorItemClick(View view, int position) {

    }
}
